﻿using System;
using System.IO;

namespace Esponce.QRCode
{
	public class GenerateEventArgs : EventArgs
	{
		/// <summary>
		/// Gets or sets an error that may have occurred while processing the request.
		/// </summary>
		public Exception Error
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets QR Code image.
		/// </summary>
		public Stream Stream
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets length of stream.
		/// </summary>
		public long ContentLength
		{
			get;
			set;
		}

		/// <summary>
		/// Reads the response stream as byte array.
		/// </summary>
		/// <returns>Returns read stream as byte array.</returns>
		public byte[] GetData()
		{
			var stream = this.Stream;
			int length = (int)this.ContentLength;
			byte[] buffer = new byte[length];
			stream.Read(buffer, 0, length);
			return buffer;
		}
	}
}
